/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kungkhies.jms.kungkhie.upload;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import javax.jms.Topic;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.kungkhies.jms.kungkhie.upload.KungkherKungkhie;
import javax.jms.MapMessage;

/**
 * 
 * 
 * @author clayton
 */
@Service("kungkhieUploadEnqueueService")
@Transactional(propagation = Propagation.REQUIRED)
public class KungkhieUploadEnqueueServiceImpl implements KungkhieUploadEnqueueService
{
    @Override
    public void enqueueKungkhieUpload(final String kungkher, final String kungkhie)
    {
        //Destination topic = new ActiveMQTopic("kungkhie.upload.queue");
        
        jmsTemplate.send("kungkhie.upload.queue", new MessageCreator()
        {
            @Override
            public MapMessage createMessage(Session session) throws JMSException
            {
                MapMessage mm = session.createMapMessage();
                mm.setString("kungkher", kungkher);
                mm.setString("kungkhie", kungkhie);
                return mm;
            }
        });
    }
    
    @Autowired
    JmsTemplate jmsTemplate;

    @Override
    public void enqueueStringMessage(final String kungkher)
    {
        jmsTemplate.send("kungkhie.upload.queue", new MessageCreator()
        {
            @Override
            public Message createMessage(Session session) throws JMSException
            {
                Message mm = session.createTextMessage();
                
                return mm;
            }
        });
    }
}
